import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.less']
})
export class FormComponent implements OnInit {

    @Output() getList = new EventEmitter<any>();
    instructionTypeOption = [
        {
            label: "跨境通信网络通联查询",
            value: 1,
        },
        {
            label: "跨境通信访问分析查询",
            value: 2,
        },
    ];
    executionStatusOption = [
        {
            label: "已完成",
            value: 1,
        },
        {
            label: "执行中",
            value: 2,
        },
        {
            label: "待执行",
            value: 3,
        },
    ];
    executionResultOption = [
        {
            label: "运行中",
            value: 1,
        },
        {
            label: "异常",
            value: 2,
        },
        {
            label: "成功",
            value: 3,
        },
        {
            label: "失败",
            value: 4,
        },
    ];
    searchForm: any;

    constructor(private fb: FormBuilder, private message: NzMessageService) {}

    ngOnInit(): void {
        this.initSearchForm();
    }

    initSearchForm() {
        this.searchForm = this.fb.group({
            timeRange: [null],
            instructionId:"",
            instructionType: [],
            executionStatus: [],
            executionResult: [],
        });
    }

    search() {
        if (this.searchForm.invalid) {
            this.message.error("请填写完整信息");
            return;
        }
        this.getList.emit({
            pageNum: 1,
            pageSize: 10,
            instructionId: this.searchForm.get("instructionId").value,
            instructionType: this.searchForm.get("instructionType").value,
            executionStatus: this.searchForm.get("executionStatus").value,
            executionResult: this.searchForm.get("executionResult").value,
            startTime: this.searchForm.get("timeRange").value ? this.searchForm.get("timeRange").value[0].getTime() : null,
            endTime: this.searchForm.get("timeRange").value ? this.searchForm.get("timeRange").value[1].getTime() : null,
        });
    }

    resetForm() {
        this.searchForm.reset();
    }
}
